import java.io.*;
import java.util.*;

public class FileUpdate1{
  public static void main(String[] args)throws IOException{
    // 1. Create a FileInputStream object
    FileInputStream instream = new FileInputStream("input.txt");

    // 2. Wrap the input stream in a scanner
    Scanner fscanner = new Scanner(instream);

    // 3. Count the number of integers in the file
    int numIntegers = 0;
    while(fscanner.hasNextInt()){
    	fscanner.nextInt();
    	numIntegers++;
    }

    //4. Reset the file-read pointer to point to the beginning of the file
    fscanner.close();
    instream = new FileInputStream("input.txt");
    fscanner = new Scanner(instream);

    // 5. Create an array with numIntegers size
    int[] array = new int[numIntegers];

    // 6.  Initialize the array with the file contents
    for(int k = 0; k < array.length; k++)
      array[k] = fscanner.nextInt();

    // 7. Close the input stream
    fscanner.close();

     // 8. Update the array
     for(int k = 0; k < array.length; k++)
       array[k] += 2;

     // 9. Create an associated output stream
     PrintWriter pwriter = new PrintWriter("input.txt");

     // 10. Overwrite the file with the values of the updated array
     for(int k = 0; k <= array.length - 2; k++)
       pwriter.println(array[k]);

       pwriter.print(array[array.length - 1]);   // Write last element without generating new line

     // 11. Close the output stream
     pwriter.close();
     // 12. For convenience inform the user that the file has been updated
     System.out.println("The file input.txt has been updated . . .");
  }
}
